<template>
  <div>
    <page-main>
      <el-form :model="search" inline>
        <el-form-item label="计划名称">
          <el-input v-model="search.plan_name" placeholder="请输入"></el-input>
        </el-form-item>

        <el-form-item label="签到时间">
          <el-date-picker v-model="search.sign_in_time" type="date" placeholder="请选择" value-format="YYYY-MM-DD" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getDateList(1)" size="mini">搜索</el-button>
          <el-button type="warning" @click="reset" size="mini">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableData" border style="width: 100%" height="50vh" v-loading="loading">
        <el-table-column prop="plan_name" label="计划名称"></el-table-column>
        <el-table-column prop="wb_unit_name" label="维保单位"></el-table-column>
        <el-table-column prop="unit_name" label="社会单位"></el-table-column>
        <!-- <el-table-column prop="plan_user_id" label="执业人员"></el-table-column> -->
        <el-table-column prop="task_nature" label="任务性质" :formatter="taskNatureFormatter"></el-table-column>

        <el-table-column prop="sign_in_time " label="签到时间">
          <template #default="scope">{{ $getDateTime(scope.row.sign_in_time) }}</template>
        </el-table-column>
        <el-table-column prop="sign_in_longitude " label="签到经纬度">
          <template #default="scope">{{ scope.row.sign_in_longitude }}{{ ',' + scope.row.sign_in_latitude }}</template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @current-change="getDateList"
          v-model:currentPage="tableDataInfo.current_page"
          :total="tableDataInfo.total"
          :page-count="tableDataInfo.last_page"
          background
          layout="total,prev, pager, next, jumper"
        >
        </el-pagination>
      </div>
    </page-main>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      tableDataInfo: '',
      search: {},
      upDataUrl: import.meta.env.DEV ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL,
      loading: false
    }
  },
  created() {
    this.getDateList()
  },
  methods: {
    reset() {
      this.search = {}
      this.getDateList(1)
    },
    taskNatureFormatter(row, column, cellValue, index) {
      let temp = {
        1: '计划内',
        2: '业主通知',
        3: '主机报警'
      }
      return temp[cellValue]
    },
    getDateList(page) {
      let unit_id = localStorage.getItem('fa_user_info')
      this.loading = true
      let pageNum = 1
      if (page) pageNum = page
      this.$api
        .post('/unit/Dashboard/dangerList', {
          type: 'outPlanLocationTotal',
          ...this.search,
          unit_id: JSON.parse(unit_id).unit_id
        })
        .then((res) => {
          this.tableData = res.data.list
          delete res.data.data
          this.tableDataInfo = res.data
        })
        .finally(() => {
          this.loading = false
        })
    }
  }
}
</script>

<style scoped>
.block {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
</style>
